﻿#Requires AutoHotkey v2.0

; ================


; 定时（分钟）
STOP_AFTER := 30


; ================

Wnd          := Gui(, "AHK 定时器")
Wnd.OnEvent("Close", Wnd_Close)
Wnd.SetFont("c0055FF s14 bold")

TotalText    := Wnd.AddText(, "定时停止音乐播放：" . STOP_AFTER . " 分钟")

Wnd.SetFont("c001199 s12 bold")

SleepCheck   := Wnd.AddCheckBox("vSleepCheck", "停止播放后电脑睡眠")

RemainText   := Wnd.AddText(, "剩余：" . STOP_AFTER . " 分钟")
TimeProgress := Wnd.Add("Progress", "w300 h20 cBlue vTimeProgress", 100)
AliveProgress := Wnd.Add("Progress", "w300 h20 cBlue vAliveProgress", 100)

Wnd.Show

TimeRemaining := STOP_AFTER

Loop STOP_AFTER {
    RemainText.Text := "⌚剩余：" . (TimeRemaining + 1) . " 分钟"
    TimeProgress.Value := ((TimeRemaining / STOP_AFTER) * 100)
    TimeRemaining -= 1
    
    Loop 6 {
        SecondCounter := 10
        Loop 10 {
            AliveProgress.Value := SecondCounter * 5
            SecondCounter -= 1
            Sleep(1000)
        }
    }
}

Send("{Media_Stop}")

if(SleepCheck.Value) {
    ; 到时间使电脑睡眠
    DllCall("PowrProf\SetSuspendState", "int", 0, "int", 0, "int", 0)
}

; ==================

; 窗口关闭时终止脚本运行
Wnd_Close(thisWnd) {
    ;if MsgBox("Are you sure you want to close the GUI?",, "y/n") = "No"
    ;    return true  ; true = 1
    ExitApp
}